package Day18;

import java.util.HashSet;
import java.util.Scanner;
import java.util.Set;

public class Main {

    public static Set<Character> set = new HashSet<>();


    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        iniSet(set);

        while (scanner.hasNextLine()) {
            String s = scanner.nextLine();
            s = s.toUpperCase();
            String ss = scanner.nextLine();
            ss = ss.toUpperCase();

            boolean b = isMatched(s, ss);
            System.out.println(b);
        }
    }

    public static boolean isMatched (String toTest, String origin) {

        boolean originEnd = false;
        boolean toTestEnd = false;
        int tl = toTest.length();
        int ol = origin.length();

        int j = 0, i;
        for (i = 0; i < tl && j < ol; i++) {

            char c = toTest.charAt(i);
            //?相当于配对成功, 接着往下走
            if (c == '?') {
                if (set.contains(origin.charAt(j))) {
                    j++;
                } else {
                    return false;
                }
            } else if (c == '*') {
                //假如*已经是最后一个字符: true
                if (i + 1 == tl) {
                    return true;
                }
                //*不是最后一个字符: 找到origin中下一个与toTest匹配的字符为止, 找不到就false
                else {
                    //c为*后一个不为*的字符
                    while (c == '*') {
                        c = toTest.charAt(++i);
                    }

                    if (c == '?') {
                        if (set.contains(origin.charAt(j))) {
                            j++;
                        } else {
                            return false;
                        }
                    } else {
                        while (j < ol) {
                            //配对成功为止
                            if (c == origin.charAt(j)) {
                                if (j + 1 < ol) {
                                    //要求origin不是连续相等, 否则继续遍历origin
                                    if (origin.charAt(j + 1) != c) {
                                        j++;
                                        break;
                                    } else {
                                        j++;
                                    }
                                } else {
                                    break;
                                }
                            } else {
                                j++;
                            }
                        }
                    }
                    //没有在origin中找到能与toTest的*后面匹配的字符: false
                    if (j >= ol) {
                        return false;
                    }
                }
            } else if (set.contains(c)) {
                //配对成功: 继续遍历
                if (c == origin.charAt(j)) {
                    j++;
                } else {
                    return false;
                }
            }
            //非法字符: false
            else {
                return false;
            }

            if (j == ol - 1) {
                originEnd = true;
            }
            if (i == tl - 1) {
                toTestEnd = true;
            }
        }

        //上面循环走完说明toTest遍历完了
        //最后要求j也遍历完true
        return originEnd && toTestEnd;
    }
    
    public static void iniSet (Set<Character> set) {
        for (int i = 'A'; i <= 'Z'; i++) {
            set.add((char)i);
        }
        for (int i = 48; i <= 57; i++) {
            set.add((char)i);
        }
    }

    public static void main0(String[] args) {
        Scanner scanner = new Scanner(System.in);
        while(scanner.hasNextInt()) {
            int n = scanner.nextInt();

            //第n个月的兔子树是一定的
            System.out.println(getRabbits(n));
        }
    }

    public static int getRabbits (int n) {
        if (n <= 0) {
            return -1;
        }

        //分别表示一个月大兔子, 两个月大兔子, 可生孩子的兔子
        int young1 = 1;
        int young2 = 0;
        int adult = 0;
        int sum = 1;
        for (int i = 1; i < n; i++) {
            adult += young2;
            young2 = young1;
            young1 = adult;
            sum = young1 + young2 + adult;
        }
        return sum;
    }

}
